package net.xumf.domain.master;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.annotations.*;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.Date;

@Data
@Entity
@Table(name = "system_user2")
@ApiModel(description = "用户对象")
@DynamicInsert
@DynamicUpdate
public class SystemUser implements Serializable {

    @ApiModelProperty(value = "用户id", hidden = true)
    @Id
    @SequenceGenerator(name = "user_generator", sequenceName = "user_generator", initialValue = 23)
    @GeneratedValue(generator = "user_generator")
    private Long id;

    @ApiModelProperty(value = "用户名")
    @Column(name = "username", unique = true, nullable = false, length = 50)
    private String username;

    @ApiModelProperty(value = "登录名")
    @Column(name = "login_name", unique = true, nullable = false, length = 25)
    private String loginName;

    @ApiModelProperty(value = "密码")
    @Column(name = "password", nullable = false)
    private String password;

    @ApiModelProperty(value = "盐值", hidden = true)
    @Column(name = "salt", length = 6, nullable = false)
    private Integer salt;

    @ApiModelProperty(value = "用户状态")
    @Column(name = "status", length = 3, nullable = false, columnDefinition = "smallint default 10")
    private Integer status;

    @ApiModelProperty(value = "角色，以逗号分开")
    @Column(name = "roles", nullable = false, columnDefinition = "varchar default ''")
    private String roles;

    @ApiModelProperty(value = "邮箱")
    @Column(name = "email")
    private String email;

    @ApiModelProperty(value = "手机")
    @Column(name = "mobile", length = 30)
    private String mobile;

    @ApiModelProperty(value = "创建时间", hidden = true)
    @Column(name = "created_at", nullable = false, insertable = false, updatable = false, columnDefinition = "timestamp default current_timestamp")
    @Generated(GenerationTime.INSERT)
    @Temporal(TemporalType.TIMESTAMP)
    private Date createdAt;

    @ApiModelProperty(value = "更新时间", hidden = true)
    @Column(name = "updated_at", nullable = false, insertable = false, columnDefinition = "timestamp default current_timestamp")
    @Generated(GenerationTime.ALWAYS)
    @Temporal(TemporalType.TIMESTAMP)
    @DateTimeFormat()
    private Date updatedAt;
}